class Solution
{
public:
    int removeElement(vector<int> &nums, int val)
    {
        int n = nums.size();
        int removed = 0;
        int now = 0;
        int next = 0;
        while (true)
        {
            if (next == n)
            {
                break;
            }
            if (nums[next] == val)
            {
                ++next;
                ++removed;
            }
            else
            {
                nums[now] = nums[next];
                ++next;
                ++now;
            }
        }
        return n - removed;
    }
};